<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:ct="http://combitech.se/facelets/order">

<ui:composition template="/WEB-INF/templates/mainOrder.xhtml">
	<ui:define name="pageTitle">Registrera kund</ui:define>
	<ui:define name="pageHeader">Header</ui:define>
	<ui:define name="content">
		<rich:panel style="width:800px">
			<f:facet name="header">
				<h:outputText value="Registrera kund" />
			</f:facet>
			<h:form id="reg">

				<ct:customerPanel panelId="newCustomerPanel"
					customer="#{newCustomer}" />

				<p>
					<h:panelGrid columns="2">
						<a4j:commandButton id="save" action="#{customerController.save()}"
							value="Spara" styleClass="register" execute="newCustomerPanel"
							render="newCustomerPanel,customerList" />
						<rich:messages globalOnly="true" />
					</h:panelGrid>
				</p>

				<br />

				<div id="newMemberMessages" class="update" />

				<rich:collapsiblePanel id="customerList" header="Kunder"
					headerClass="header" title="Klicka för att expandera/dölja">
					<h:panelGroup rendered="#{empty customers}">
						<em>Inga registrerade kunder.</em>
					</h:panelGroup>
					<rich:dataTable id="customerTable" var="_customer"
						value="#{customers}" rendered="#{not empty customers}"
						style="width : 100%">
						<rich:column id="view">
							<a4j:commandLink styleClass="no-decor" render="customerPanel"
								execute="@this"
								oncomplete="#{rich:component('customerPopup')}.show()">
								<h:graphicImage value="../resources/gfx/document-edit.png" />
								<f:setPropertyActionListener
									target="#{customerController.customer}" value="#{_customer}" />
							</a4j:commandLink>
						</rich:column>
						<rich:column id="delete">
							<a4j:commandLink styleClass="no-decor" render="customerList"
								execute="@this" action="#{customerController.delete()}">
								<h:graphicImage value="../resources/gfx/edit-delete-6.png" />
								<f:setPropertyActionListener
									target="#{customerController.customer}" value="#{_customer}" />
							</a4j:commandLink>
						</rich:column>
						<rich:column id="customer_fname">
							<f:facet name="header">Förnamn</f:facet>
                      #{_customer.firstName}
                   </rich:column>
						<rich:column id="customer_lname">
							<f:facet name="header">Efternamn</f:facet>
                      #{_customer.lastName}
                   </rich:column>
						<rich:column id="customer_email">
							<f:facet name="header">Epost</f:facet>
                      #{_customer.email}
                   </rich:column>
						<rich:column id="customer_phone">
							<f:facet name="header">Telefon</f:facet>
                      #{_customer.phone}
                   </rich:column>
						<rich:column id="customer_rest_url">
							<f:facet name="header">REST URL</f:facet>
							<a href="#{request.contextPath}/rest/customers/#{_customer.id}"
								target="_rest_customer">/rest/customers/#{_customer.id}</a>
						</rich:column>
						<f:facet name="footer">
                      REST URL för alla kunder: <a
								href="#{request.contextPath}/rest/customers" target="_rest_all">/rest/customers</a>
						</f:facet>
					</rich:dataTable>
				</rich:collapsiblePanel>


				<rich:popupPanel id="customerPopup" modal="true"
					onmaskclick="#{rich:component('customerPopup')}.hide()"
					domElementAttachment="form" autosized="true">
					<f:facet name="header">
						<h:outputText value="Kunddetaljer" />
					</f:facet>
					<f:facet name="controls">
						<h:outputLink value="#"
							onclick="#{rich:component('customerPopup')}.hide(); return false;">
	                   X
	                </h:outputLink>
					</f:facet>
					<h:panelGroup id="customerPanel">

						<ct:customerPanel panelId="detailCustomer"
							customer="#{customerController.customer}" prefix="x" />
						<br />
						<h:panelGrid columns="2">
							<a4j:commandButton id="change"
								action="#{customerController.change()}" value="Spara"
								styleClass="register" execute="customerPanel"
								render="customerList"
								oncomplete="#{rich:component('customerPopup')}.hide(); return false;">
							</a4j:commandButton>
							<rich:messages globalOnly="true" />
						</h:panelGrid>
					</h:panelGroup>
				</rich:popupPanel>
			</h:form>
		</rich:panel>
	</ui:define>
</ui:composition>
</html>